<?php
namespace Api\Controller;

class LoginController extends CommonController {
    public function appLogin()
    {
        $shop_phone = $_POST['phone']?trim($_POST['phone']):'';
        $shop_login_pass = $_POST['password']?trim($_POST['password']):'';
        if(empty($shop_phone)) $this->renderError('请输入手机号码');
        if(empty($shop_login_pass)) $this->renderError('请输入登陆密码');
        $t_shop_list = M("shop_list");
        if($shop_info = $t_shop_list->where("`shop_phone`='$shop_phone'")->find()){
            if(think_weiphp_md5($shop_login_pass) == $shop_info['shop_login_pass']){
                $user_token = sha1(uniqid(md5(microtime(true)),true).$shop_info['id']);
                $user_data['uid'] = $shop_info['id'];
                S($user_token,$user_data,3600*24*7);
                $this->renderSuccess(['user_token'=>$user_token]);
            }else{
                $this->renderError('对不起，帐号密码错误');
            }
        }else{
            $this->renderError('对不起，帐号密码错误');
        }
    }
}